//
//  StatusRetweedCell.swift
//  Weibo
//
//  Created by 孙明海 on 16/2/22.
//  Copyright © 2016年 孙明海. All rights reserved.
//

import UIKit
import FFLabel

class StatusRetweedCell: StatusCell {
    
    override var statusViewModel: StatusViewModel? {
        didSet {
            
            retweedLable.text = statusViewModel?.retweedText
            retweedLable.attributedText = EmoticonManager.sharedManager.emotionText(retweedLable.text ?? "", font: retweedLable.font)
            
            
            pictureView.statusViewModel = statusViewModel
            pictureView.snp_updateConstraints { (make) -> Void in
                
                let offset = (statusViewModel?.thumbnailUrls?.count > 0) ? StatusCellMargin : 0
                make.top.equalTo(retweedLable.snp_bottom).offset(offset)
            }
        }
    }
    

    // MARK: - 懒加载控件
    /// 背景按钮
    lazy var backButton: UIButton = {
        let button = UIButton()
        button.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        return button
    }()
     ///  转发字段lable
    lazy var retweedLable: FFLabel = FFLabel(title: "转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博",
        fontSize: 14,
        color: UIColor.darkGrayColor(),
        screenInset: StatusCellMargin)
    /// 设置界面
    override func setupUI() {
        super.setupUI()
        // 添加控件
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(retweedLable, aboveSubview: backButton)
        // 设置布局
        backButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLable.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(bottomView.snp_top).offset(-StatusCellMargin)
        }
        retweedLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(backButton.snp_top).offset(StatusCellMargin)
            make.left.equalTo(backButton.snp_left).offset(StatusCellMargin)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweedLable.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweedLable)
            make.width.equalTo(300)
            make.height.equalTo(90)
        }
        
        retweedLable.labelDelegate = self
    }

}
